package com.yserp.project.erp.order.sampleregistration.controller;

import com.yserp.common.utils.poi.ExcelUtil;
import com.yserp.framework.aspectj.lang.annotation.Log;
import com.yserp.framework.aspectj.lang.enums.BusinessType;
import com.yserp.framework.web.controller.BaseController;
import com.yserp.framework.web.domain.AjaxResult;
import com.yserp.framework.web.page.TableDataInfo;
import com.yserp.project.erp.order.sampleregistration.domain.SampleRigistration;
import com.yserp.project.erp.order.sampleregistration.service.ISampleRigistrationService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * 样品登记Controller
 *
 * @author yserp
 * @date 2022-08-01
 */
@Controller
@RequestMapping("/order/sampleregistration")
public class SampleRigistrationController extends BaseController {
    private String prefix = "erp/order/sampleregistration";

    @Autowired
    private ISampleRigistrationService sampleRigistrationService;

    @RequiresPermissions("order:sampleregistration:view")
    @GetMapping()
    public String sampleregistration() {
        return prefix + "/sampleregistration";
    }

    /**
     * 查询样品登记列表
     */
    @RequiresPermissions("order:sampleregistration:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(SampleRigistration sampleRigistration) {
        startPage();
        List<SampleRigistration> list = sampleRigistrationService.selectSampleRigistrationList(sampleRigistration);
        return getDataTable(list);
    }

    /**
     * 导出样品登记列表
     */
    @RequiresPermissions("order:sampleregistration:export")
    @Log(title = "样品登记", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(SampleRigistration sampleRigistration) {
        List<SampleRigistration> list = sampleRigistrationService.selectSampleRigistrationList(sampleRigistration);
        ExcelUtil<SampleRigistration> util = new ExcelUtil<SampleRigistration>(SampleRigistration.class);
        return util.exportExcel(list, "样品登记数据");
    }

    /**
     * 新增样品登记
     */
    @GetMapping("/add")
    public String add() {
        return prefix + "/add";
    }

    /**
     * 新增保存样品登记
     */
    @RequiresPermissions("order:sampleregistration:add")
    @Log(title = "样品登记", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(SampleRigistration sampleRigistration) {
        return toAjax(sampleRigistrationService.insertSampleRigistration(sampleRigistration));
    }

    /**
     * 修改样品登记
     */
    @RequiresPermissions("order:sampleregistration:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap) {
        SampleRigistration sampleRigistration = sampleRigistrationService.selectSampleRigistrationById(id);
        mmap.put("sampleRigistration", sampleRigistration);
        return prefix + "/edit";
    }

    /**
     * 修改保存样品登记
     */
    @RequiresPermissions("order:sampleregistration:edit")
    @Log(title = "样品登记", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(SampleRigistration sampleRigistration) {
        return toAjax(sampleRigistrationService.updateSampleRigistration(sampleRigistration));
    }

    /**
     * 删除样品登记
     */
    @RequiresPermissions("order:sampleregistration:remove")
    @Log(title = "样品登记", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(sampleRigistrationService.deleteSampleRigistrationByIds(ids));
    }

    /**
     * 转化为客户
     */
    @PostMapping("/transCustomer")
    @ResponseBody
    public AjaxResult transCustomer(Long id) {
        return toAjax(sampleRigistrationService.transCustomer(id));
    }


}
